//公用方法
//判断是否是图片
const image = function (file) {
    const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png'
  
    if (!isJpgOrPng) {
      return false
      // this.$message.error('你上传的不是图片');
    } else {
      return true
    }
  }
  //判断是否是pdf
  const pdf = function (file) {
    const isPdf = file.type === 'application/pdf'
    if (!isPdf) {  
      return false
      // this.$message.error('你上传的不是PDF');
    } else {
      return true
    }
  }
  //页码默认为1
  const pageNum = function (val) {
    if (val == 0) {
      return 1
    } else {
      return val
    }
  }
  
  //数据默认为0
  const default0Fn = function (val) {
    if (typeof val === 'undefined' || val === null || val.toString().trim() === '') {
      return 0
    }
    return val
  }
  // oss上传方法
  import { uploadOSS } from '@/utils/oss.js'
  const ossUploadUrl = async function (blob, fileName, fileUid, dir) {
    let fileUrl = await uploadOSS(blob, fileName, dir)
    let obj = { url: fileUrl, name: fileName, id: fileUid }
    return obj
  }
  
  //退出方法
//   import { logout } from '@/api/loginout'
//   import store from '../store/index.js'
//   import { message } from 'ant-design-vue'
//   const logOutFn = function (val) {
//     message.destroy()
//     message.warning('会话失效，请重新登录。')
  
//     logout({}).then((res) => {
//       localStorage.clear()
//       console.log(store.state.appPublicUrl);
//       top.window.location =
//         process.env.VUE_APP_CAS_URL + '/logout?service=' + encodeURIComponent(store.state.appPublicUrl)
//     })
//   }
  
  //判断角色
  const isRole = function (data){
    let arr = ['sg', 'jl', 'zhb', 'jg']
    let roleKey =-1
    for (let index = 0; index < data.length; index++) {
      let count = arr.indexOf(data[index])
      if (count >= roleKey) {
        roleKey = count
      }
    }
    if (arr[roleKey]) {
      return arr[roleKey]
    }else{
      return ''
    }
  }
  
  
  
  
  export default { image, pdf, pageNum, default0Fn ,isRole,ossUploadUrl}
  